#pragma once

namespace micro
{
namespace core
{


class QGlobalMemory
{

    HGLOBAL hand;
public:
    void * ptr;
    QGlobalMemory() : hand( 0 ), ptr( 0 )
    {
    }
    QGlobalMemory( HGLOBAL hand_ ) : hand( hand_ ), ptr( 0 )
    {
        if ( hand )
        {
            ptr = ::GlobalLock( hand );
        }
    }
    ~QGlobalMemory()
    {
        ASSERT( !ptr );
    }
    void Allocate( size_t bytes )
    {
        hand = ::GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, bytes );

        if ( hand )
        {
            ptr = ::GlobalLock( hand );
        }
    }
    HGLOBAL Unlock()
    {
        ASSERT( ptr );
        HGLOBAL handCopy = hand;
        ::GlobalUnlock( hand );
        ptr = 0;
        hand = 0;
        return handCopy;
    }
    void SetClip( UINT uFormat )
    {
        ::SetClipboardData( uFormat, Unlock() );
    }
    operator bool()
    {
        return ptr != 0;
    }
    SIZE_T QSize()
    {
        return ::GlobalSize( hand );
    }
};




}//utils
}//micro